import Vue from "vue"
import VueRouter from 'vue-router'

Vue.use(VueRouter)


import home from '../pages/home.vue'
import follow from '../pages/follow.vue'
import column from '../pages/column.vue'
import user from '../pages/user.vue'
import economic from '../pages/economic.vue'
import life from '../pages/life.vue'
import reg from '../pages/reg.vue'
import login from '../pages/login.vue'
import Nopage from '../pages/no-page.vue'
import detail from '../pages/detail.vue'
import video from '../pages/video.vue'
import now from '../pages/now.vue'
import idea from '../pages/idea.vue'
import question from '../pages/question.vue'
import axios from './axios.js'

// import SkeletonScreen from '../components/Skeleton-screen.vue'

// import { List } from 'vant';

let routes =[
	
	// {path: '/skeleton',	component: SkeletonScreen},
	
	{path:'/home',component:home},
	{path:'/home/:_id',component:detail,name:'home-detail',meta:{path:'detail'}},
	{path:'/follow',component:follow},
	{path:'/follow/:_id',component:detail,meta:{path:'detail'}},
	{path:'/column',component:column},
	{path:'/column/:_id',component:detail,meta:{path:'detail'}},
	{path:'/user',component:user},
	{path:'/economic',component:economic},
	{path:'/life',component:life},
	{path:'/video',component:video},
	{path:'/now',component:now},
	{path:'/idea',component:idea},
	{path:'/question',component:question},
	{path:'/login',component:login},
	{path:'/reg',component:reg},
	{path:'/',redirect:'/home'},
	{path:'*',component:Nopage}
];
let router = new VueRouter({
	routes,
	mode:'history'
})

router.beforeEach((to,from,next)=>{
	//1. 只校验token==>组件还需读取自身数据
	let path = to.path;
	if(path.includes('/login') || path.includes('/reg')){
	  next()
	}else{
		// 只校验toke
		axios({
			url:'/is-token',		
		}).then(
		res=>{
		  if(res.err===2){
		    // console.log('守卫',res)
		    next(`/login?Path=${to.fullPath}`)
		  }else{
		    next()
		  }
		}
		)
	}
	
	
	
	
})

export default router;